/**
 * token-用户登录信息
 * @type {exports}
 */
var encryption = require('./encryption.utils');
module.exports = {
  create: function (req) {
    var key = {user: req.param('name'), pass: encryption.md5(req.param('pwd')), ua: req.header('user-agent')};
    return encryption.aes(JSON.stringify(key));
  },
  getToken: function (req) {
    var token = JSON.parse(encryption.aes(req.param('_token'), true) || '{}');
    if (!'ua' in token || token.ua !== req.header('user-agent')) {
      return {user: '', pass: '', ua: ''};
    }
    return token;
  }
};